package dishi;

import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.Statement;
import java.util.LinkedList;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

public class dir extends JFrame {

	private JPanel contentPane;
	private JTextField input;

	private LinkedList<record> content = new LinkedList<record>();

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					dir frame = new dir();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});

	}

	/**
	 * Create the frame.
	 */
	public dir() {

		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		input = new JTextField();
		input.setBounds(61, 20, 300, 80);
		contentPane.add(input);
		input.setColumns(10);
		JTextArea output = new JTextArea();
		output.setBounds(73, 160, 300, 80);
		contentPane.add(output);
		JButton search = new JButton("search");
		search.addActionListener((ActionListener) new ActionListener() {
			public void actionPerformed1(ActionEvent e) {
				String str = input.getText();

				try {
					Class.forName("com.mysql.jdbc.Driver");

					Connection con = DriverManager.getConnection(
							"jdbc:mysql://localhost:3306/asda?useUnicode=true&characterEncoding=utf-8", "root",
							"I1jyb770gz+<");

					Statement sql = con.createStatement();

					ResultSet rs = executeQuery("select*from yhy");
					boolean flag = true;
					String english = null;
					String chinese = null;

					while (rs.next()) {
						english = rs.getString("english");
						chinese = rs.getString("chinese");

						if (chinese.equals(str)) {
							output.setText(english);
							flag = false;
						}
						if (english.equals(str)) {
							output.setText(chinese);
							flag = false;
						}
					}
					if (flag) {
						output.setText("ûҵ");
					}
				} catch (ClassNotFoundException e1) {

					e1.printStackTrace();
				}

			}

			private ResultSet executeQuery(String string) {
				// TODO Auto-generated method stub
				return null;
			}

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				
			}

		});
		search.setBounds(156, 110, 97, 23);
		contentPane.add(search);

	}
}
